package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.record.OccupaVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by JiangAn on 2018/5/25.
 */

public class OccupationInfoAdapter extends LemonRcvAdapter<OccupaVo> {
    private RecyclerTClickListener<OccupaVo> mListener;

    public OccupationInfoAdapter(@Nullable List<OccupaVo> data, RecyclerTClickListener<OccupaVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new OccupationInfoAdapter.OccupaItem();
    }

    public class OccupaItem implements AdapterItem<OccupaVo> {
        @Bind(R.id.tv_space_name)
        TextView tvSpaceName;
        @Bind(R.id.tv_damage_type)
        TextView tvDamageType;
        @Bind(R.id.tv_cause_illness)
        TextView tvCauseIllness;
        @Bind(R.id.tv_space_remark)
        TextView tvSpaceRemark;
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;
        private OccupaVo data;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_occupation_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(OccupaVo occupaVo, int position) {
            data = occupaVo;
            pos = position;
            tvSpaceName.setText(CommonUtil.avoidNullString(occupaVo.getHarm_name()));
            tvDamageType.setText(CommonUtil.avoidNullString(occupaVo.getHarm_type()));
            tvCauseIllness.setText(CommonUtil.avoidNullString(occupaVo.getOccupational_disease()));
            tvSpaceRemark.setText(CommonUtil.avoidNullString(occupaVo.getRemarks()));
        }
    }
}
